package cn.edu.zafu.bigdata.XuShuXin.Exp1119;
import java.util.Scanner;
/**
 * @author: aluvfy
 * @description:
 * @date: 2024/11/19 11:11
 */
public class MainSystem_xsx {
    public static void main(String[] args) {
        StudentManager_xsx manager = new StudentManager_xsx();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("======= 学生信息管理系统 =======");
            System.out.println("1. 添加学生信息");
            System.out.println("2. 检索学生信息");
            System.out.println("3. 更新学生信息");
            System.out.println("4. 删除学生信息");
            System.out.println("5. 退出程序");
            System.out.print("请输入操作编号 (1-5): ");
            String choice = scanner.nextLine();

            switch (choice) {
                case "1":
                    addStudent(manager, scanner);
                    break;
                case "2":
                    searchStudent(manager, scanner);
                    break;
                case "3":
                    updateStudent(manager, scanner);
                    break;
                case "4":
                    deleteStudent(manager, scanner);
                    break;
                case "5":
                    System.out.println("程序结束。");
                    return;
                default:
                    System.out.println("无效的选项，请重新选择。");
            }
        }
    }

    private static void addStudent(StudentManager_xsx manager, Scanner scanner) {
        System.out.print("请输入学号：");
        String id = scanner.nextLine();
        System.out.print("请输入姓名：");
        String name = scanner.nextLine();
        System.out.print("请输入电话：");
        String phone = scanner.nextLine();
        manager.addStudent(id, name, phone);
    }

    private static void searchStudent(StudentManager_xsx manager, Scanner scanner) {
        while (true) {
            System.out.print("请输入学号（或输入QUIT返回）：");
            String id = scanner.nextLine();
            if (id.equalsIgnoreCase("QUIT")) {
                return;
            }
            manager.searchStudent(id);
        }
    }

    private static void updateStudent(StudentManager_xsx manager, Scanner scanner) {
        while (true) {
            System.out.print("请输入要更新的学号（或输入QUIT返回）：");
            String id = scanner.nextLine();
            if (id.equalsIgnoreCase("QUIT")) {
                return;
            }
            System.out.print("请输入新的姓名：");
            String name = scanner.nextLine();
            System.out.print("请输入新的电话：");
            String phone = scanner.nextLine();
            manager.updateStudent(id, name, phone);
        }
    }

    private static void deleteStudent(StudentManager_xsx manager, Scanner scanner) {
        while (true) {
            System.out.print("请输入要删除的学号（或输入QUIT返回）：");
            String id = scanner.nextLine();
            if (id.equalsIgnoreCase("QUIT")) {
                return;
            }
            manager.deleteStudent(id);
        }
    }
}